<template>
  <el-container>
    <el-header class="homeHeader">
      <div class="title">用户权限管理系统</div>
      <el-dropdown class="userInfo" @command="handleCommand">
        <span class="el-dropdown-link">
          {{ user.userName }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
          <el-dropdown-item command="logOut">注销登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu router>
          <el-menu-item index="/home">首页</el-menu-item>
        </el-menu>
        <el-menu router>
          <el-submenu index="1">
            <template slot="title">系统管理</template>
            <el-menu-item index="/userManage">用户管理</el-menu-item>
            <el-menu-item index="/roleManage">角色管理</el-menu-item>
            <el-menu-item index="/menuManage">菜单管理</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 面包屑效果  如果是在首页就不需要了 -->
        <el-breadcrumb
          separator-class="el-icon-arrow-right"
          v-if="this.$router.currentRoute.path != '/home'"
        >
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <!-- this.$router.currentRoute.name获取当前路由的名字 -->
          <el-breadcrumb-item>{{
            this.$router.currentRoute.name
          }}</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="homeWelcome" v-if="this.$router.currentRoute.path == '/home'">
          欢迎访问用户权限管理系统
        </div>
        <!-- 这个标签 -->
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import "../router/index";


export default {
  name: "Home",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user")).data,
    };
  },
  methods: {
    handleCommand(command) {
      if (command === "logOut") {
        // 注销登录
        this.$confirm("你将注销登录，是否继续", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.postRequest("/logOut");
            window.sessionStorage.removeItem("user");
            window.localStorage.removeItem("Authorization");
            this.$router.replace("/");
            this.$message({
              type: "success",
              message: "注销成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消操作",
            });
          });
      }
    },
  },
};
</script>

<style>
.homeHeader {
  background: #2685e4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  box-sizing: border-box;
}

.homeHeader .title {
  font-size: 30px;
  font-family: 正楷;
  color: #ffffff;
}

.el-dropdown-link {
  cursor: pointer;
  font-size: 20px;
  color: #ffffff;
}

.homeWelcome{
  text-align: center;
  font-size:30px ;
  font-family: 华文楷体;
  color: #2685e4;
}
</style>
